{% set dff_api_title = "AlibabaCloud-OceanBase Collection" %}

{% extends "base_template" %}
{% block import %}
{{ super() }}
import integration_alibabacloud_oceanbase__main as obj_main
import integration_alibabacloud_oceanbase_slowlog__main as slowlog_main
import integration_alibabacloud_oceanbase_metric__main as monitor_main
{% endblock %}

{% block account %}
{{ super() }}
{% endblock %}

{% block collect_configs %}
collector_configs = {
    'regions': {{ repr(collector.regions) }}
}

monitor_configs = {
    'targets': [
        # Cluster
        {
            'labels': 'clusterId',
            'metrics'  : {{ repr(collector.clusterid_metrics) }}
        },
        # Database/Tenant
        {
            'labels': 'clusterId,tenantId',
            'metrics'  : {{ repr(collector.database_tenant_metrics) }}
        },
        # Replica
        {
            'labels': 'clusterId,zoneId',
            'metrics'  : {{ repr(collector.clusterid_zoneid_metrics) }}
        },
        # Host/Node
        {
            'labels': 'clusterId,serverId',
            'metrics'  : {{ repr(collector.clusterid_serverid_metrics) }}
        },
        # Obproxy Database/Tenant
        {
            'labels': 'proxyClusterId,tenantId',
            'metrics'  : {{ repr(collector.proxyclusterid_tenantid_metrics) }}
        },
        
        # Obproxy Host/Node

        {
            'labels': 'proxyClusterId,proxyServerId',
            'metrics'  : {{ repr(collector.proxyclusterid_proxyserverid_metrics) }}
        },
        {
            'labels': 'tenantId,lb_name,lbId',
            'metrics'  : {{ repr(collector.tenantid_lb_name_lbid_metrics) }}
        },
    ]
}
{% endblock %}

{% block filters%}
{% endblock %}

{% block run %}
@DFF.API('{{ dff_api_title }}', timeout=300, fixed_crontab='* * * * *')
def run():
    collectors = [
        obj_main.DataCollector(account, collector_configs),
        slowlog_main.DataCollector(account),
        monitor_main.DataCollector(account, monitor_configs),
    ]
    Runner(collectors).run()
{% endblock %}
